/**
 * Created by Administrator on 2018/6/8.
 */
function personalInfoInit($scope, $http, certusUtils1, $routeParams, CertusFormAjax) {

    $scope.close = function () {
        var index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);
    }

    $scope.mouseoverDept = function(aa){
        certusUtils1.ajax("querySuperiorDepartment",{deptCode:aa},function(res){
            $scope.show = true;
            $scope.superiorDeptName = res.data;
        })
    }

    $scope.userOperate = function () {
        //console.log($scope.sdata);
        // $.post('/userOperate',JSON.stringify($scope.baseUser),function(d){
        //     console.log(d);
        // })
        if(certusValidateNotnull()){
            CertusFormAjax.ajax("userOperateNoAuthority", $scope.baseUser, function (response) {
                if ("success" == response.data) {
                    // var index=parent.layer.getFrameIndex(window.name);
                    // parent.layer.close(index);
                    history.back();
                } else if ("logout" == response.data) {
                    certusUtils1.logout();
                }else if("error" == response.data){
                    layer.msg("保存失败");
                    history.back();
                }
            })
        }

    };

    var picker2 = $('#datetime').datetimepicker({
        format: 'YYYY-MM-DD',
        locale: moment.locale('zh-cn')
    }).on('dp.change', function (e) {
        var result = new moment(e.date).format('YYYY-MM-DD');
        if (result && !angular.isUndefined(result)) {
            $scope.baseUser.birthday = result;
            $scope.$apply();
        }
    })

    var picker3 = $('#datetime1').datetimepicker({
        format: 'YYYY-MM-DD',
        locale: moment.locale('zh-cn')
    }).on('dp.change', function (e) {
        var result = new moment(e.date).format('YYYY-MM-DD');
        if (result && !angular.isUndefined(result)) {
            $scope.baseUser.enrollTime = result;
            $scope.$apply();
        }
    })

    var param = {};
    var url = "personInfo";
    $scope.personDisabled = {};
    $scope.personDisabled.ngper = true;
    // if ($routeParams.userId && "@@@@" != $routeParams.userId) {
    //     url = "editPersonInfo";
    //     param = {
    //         "userId": $routeParams.userId
    //     }
    //     $scope.personDisabled.ngper = false;
    // }
    certusUtils1.ajax(url, param, function (result) {
            var baseUser = eval("(" + result.data + ")");
            //用于 初始化 select
            // if(baseUser.departmentUser.departmentCode){
            //     var departmentCode = baseUser.departmentUser.departmentCode;
            // }
            var sex = baseUser.sex;
            var isMarriage = baseUser.isMarriage;
            var onPost = baseUser.onPost;

            $scope.baseUser = baseUser

            //性别 选择框
            //初始化 select 选择框 数据
            $scope.sexSelect = [
                {sexName: '男', sex: "1"},
                {sexName: '女', sex: "0"}
            ];

            $scope.baseUser.sex = sex + "";

            $scope.marriageSelect = [
                {marriageName: "未婚", isMarriage: "0"},
                {marriageName: "已婚", isMarriage: "1"},
                {marriageName: "已婚已孕", isMarriage: "2"}
            ]

            $scope.onPostSelect = [
                {onPost: "1", onPostName: "在职"},
                {onPost: "0", onPostName: "离职"}
            ]

            $scope.baseUser.isMarriage = isMarriage + "";

            $scope.baseUser.onPost = onPost + "";
            CertusFormAjax.ajax("companyList", {}, function (res) {
                $scope.companySelect = eval("(" + res.data + ")");
                certusUtils1.ajax("deptedList", {"companyCode":$scope.baseUser.departmentUser.companyCode}, function (result) {
                        //初始化 公司 select 选择框 数据
                        $scope.departmentSelect = eval("(" + result.data + ")");

                        for(var i in $scope.departmentSelect){
                            if($scope.departmentSelect[i].departmentCode == $scope.baseUser.departmentUser.departmentCode){
                                $scope.departmentName = $scope.departmentSelect[i].departmentName;
                            }
                        }
                        // $scope.baseUser.departmentUser = {};
                        //初始化select 选择框
                        // $scope.baseUser.departmentUser.departmentCode = departmentCode;
                        // $scope.baseUser.birthday = $scope.baseUser.birthday.substring(0,7);
                    }
                )
            })
            // $scope.baseUser.birthday = $scope.baseUser.birthday.substring(0,7);
        }
    )

    $scope.changeDept = function(a,b,c){
        certusUtils1.ajax("deptedList", {companyCode:a}, function (res) {
            $scope.departmentSelect =eval("("+res.data+")");
            //先判断 是否 有 参数值 带过来

        })
    }


    //只保留 数字
    $scope.clearNum = function (obj, attr) {
        $scope.baseUser[attr] = $scope.baseUser[attr].replace(/\D/g, "");
    }


}